<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'modules' => [
        'member' => [
            'class' => 'frontend\modules\member\Module',
        ],
    ],
    'components' => [
        'request' => [
            'class' => \common\components\request\Request::class,
            'enableCsrfCookie' => false,
            'enableCookieValidation' => false
        ],
        'response' => [
            'on beforeSend' => function ($event) {
                /* @var $response \yii\web\Response */
                $response         = $event->sender;
                $response->format = \yii\web\Response::FORMAT_JSON;
                $response->getHeaders()->set('Access-Control-Allow-Origin', '*');
                $response->getHeaders()->set('Access-Control-Allow-Headers', 'token', 'content-type');
                if ($response->data !== null) {
                    $response->data = [
                        'message' => isset($response->data['message']) ? $response->data['message'] : "Success !",
                        'code'    => $response->statusCode == 200 ? 0 : $response->statusCode,
                        'data'    => $response->statusCode == 200 ? $response->data : (YII_DEBUG ? $response->data : null),
                    ];
                }
                $response->statusCode = 200;
            },
        ],
        'user' => [
            'identityClass' => 'common\models\Member',
            'enableAutoLogin' => false,
            'enableSession' => false,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the frontend
            'name' => 'advanced-frontend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],

    ],
    'params' => $params,
];
